package com.weishaoying.example.base.javaconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author WeiShaoying
 * @date 2018/4/3
 */
@Configuration
public class JavaConfig {
    @Bean
    public UserService userService() {
        return new UserService();
    }

    @Bean(value = "orderService")
    public OrderService orderService() {
        OrderService orderService = new OrderService();
        orderService.setUserService(userService());
        return orderService;
    }

    @Bean(name = "secondOrderService", initMethod = "init", destroyMethod = "destroy")
    @Primary
    public OrderService orderService2(UserService userService) {
        OrderService orderService = new OrderService();
        orderService.setUserService(userService);
        return orderService;
    }
}
